package br.com.divulgaqui.persistence.daoimpl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.divulgaqui.entity.PacoteAnuncio;
import br.com.divulgaqui.persistence.dao.JPAGenericDAO;
import br.com.divulgaqui.persistence.dao.PacoteAnuncioDAO;

public class PacoteAnuncioDAOImpl extends JPAGenericDAO<PacoteAnuncio>
		implements PacoteAnuncioDAO {

	public PacoteAnuncioDAOImpl(EntityManager entityManager) {
		super(entityManager);		
	}

	@Override
	public void excluir(PacoteAnuncio pacoteAnuncio) {
		getEntityManager().remove(pacoteAnuncio);		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PacoteAnuncio> listaPacotesPublicos() {
		StringBuilder sb = new StringBuilder("from PacoteAnuncio pa \n");
		sb.append(" where pa.ativo = true and pa.publicado = true \n");
		sb.append("order by valor");
		Query query = this.getEntityManager().createQuery(sb.toString());
		return query.getResultList();
	}	
}
